cd "your file location here"


use "ASESdid.dta"

*if desired set scheme plottig, permanently

*what percentage of movers do so for a job related reason

sum whymove if leavestate==1 & whymove==4 | whymove==5 | whymove==8


****exit analysis ***********************

**can use did for pretrends graph

didregress (leavestate) (ban_last) [pweight=asecwth], group(laststate) time(year)

estat trendplots, ytitle(Probability of Moving from State)

graph save ASES_did, replace 
graph export "ASESdid.pdf", as(pdf) replace 

*fail to reject null of no ptrends 
estat ptrends


**can't use didreg routine to estimate regression models because we have weights and binary outcome: didregress (ban_diff) (ban_last) if leavestate==1, group(laststate) time(year)

**so we estimate a manual DID regression 

eststo: reg leavestate i.ban_last##i.baholder ban_last##i.cb_fem i.ban_last##c.faminc_75 homeowner nchild married i.year i.laststate  [pweight=asecwth], r

eststo: reg leavestate i.ban_last##i.baholder ban_last##i.cb_fem i.ban_last##c.faminc_75 homeowner nchild married i.year i.laststate  [pweight=asecwth] if year>2021, r 

esttab using leavestate.tex, replace 


**change state models********* 

***graph and test pre trends 

didregress (changestatetype) (ban_last) [pweight=asecwth], group(laststate) time(year)

estat trendplots, ytitle(Probability of Moving to Non-ban From Ban State or Vice Versa)

graph save chstate_did, replace 
graph export "chstate_did.pdf", as(pdf) replace 

*fail to reject null of no ptrends 
estat ptrends


******manual did regressions******

eststo: reg changestatetype i.ban_last i.year i.laststate [pweight=asecwth], r

eststo: reg changestatetype i.ban_last##i.baholder i.ban_last##i.cb_fem i.ban_last##c.faminc_75 married homeowner nchild i.year i.laststate [pweight=asecwth], r

eststo: reg changestatetype i.ban_last##i.baholder i.ban_last##i.cb_fem i.ban_last##c.faminc_75 married homeowner nchild i.year i.laststate [pweight=asecwth] if year>2021, r

esttab using changestate.tex, replace 

eststo clear 



**interaction plots using model 2 above 


reg changestatetype i.ban_last##i.baholder i.ban_last##i.cb_fem i.ban_last##c.faminc_75 married homeowner nchild i.year i.laststate [pweight=asecwth], r


***college graduates*****
margins, dydx(ban_last) at(baholder = (0(1)1))
 
marginsplot, recast(bar) xtitle("") ytitle("Effect of Ban on Pr of Changing State Type") title("") xtitle("") xlabel(0 "No BA Degree" 1 "BA Degree") plotopts(color(grey%50)) ciopts(color(black)) 

gr save ba_int_chst.gph, replace 

gr export ba_int_chst.pdf, replace 


***child bearing females****

margins, dydx(ban_last) at(cb_fem = (0(1)1))


marginsplot, recast(bar) xtitle("") ytitle("Effect of Ban on Pr of Changing State Type") title("") xtitle("")  xlabel(0 "Not Childbearing Age Female" 1 "Childbearing Age Female") plotopts(color(grey%50)) ciopts(color(black)) 


gr save cbfem_int_chst.gph, replace 

gr export cbfem_int_chst.pdf, replace 


**family income 

margins, dydx(ban_last) at(faminc_75 = (0(1)1))

marginsplot, recast(bar) xtitle("") ytitle("Effect of Ban on Pr of Changing State Type") title("") xtitle("")  xlabel(0 "Bottom 3 Income Quartiles" 1 "Top Income Quartile") plotopts(color(grey%50)) ciopts(color(black)) 

gr save familyinc_int_chst.gph, replace 

gr export familyinc_int_chst.pdf, replace 

*********************
**Appendix models 
**********************

eststo: relogit leavestate ban_last dum_laststate1-dum_laststate50 dum_year2-dum_year11 [weight=asecwth] 

eststo: reg leavestate i.ban_last2 i.year i.laststate [weight=asecwth], r

eststo: reg leavestate i.ban_last2 i.year i.laststate [weight=asecwth] if year>2021, r

esttab using leavestate_app.tex, replace 

eststo clear 

***changestate analysis 

logit changestatetype i.ban_last i.year i.laststate [pweight=asecwth], r

logit changestatetype i.ban_last##i.baholder i.ban_last##i.cb_fem i.ban_last##c.faminc_75 married homeowner nchild i.year i.laststate [pweight=asecwth] if year>2021, r

logit changestatetype i.ban_last##i.baholder i.ban_last##i.cb_fem i.ban_last##c.faminc_75 married homeowner nchild i.year i.laststate [pweight=asecwth], r

*ba ints 
margins, dydx(ban_last) at(baholder = (0(1)1))

marginsplot, recast(bar) xtitle("") ytitle("Effect of Ban on Pr of Changing State Type") title("") xtitle("") xlabel(0 "No BA Degree" 1 "BA Degree") plotopts(color(grey%50)) ciopts(color(black)) 

gr save ba_int_chst_lo.gph, replace 

gr export ba_int_chst_lo.pdf, replace 

*cb fem ints 

margins, dydx(ban_last) at(cb_fem = (0(1)1))


marginsplot, recast(bar) xtitle("") ytitle("Effect of Ban on Pr of Changing State Type") title("") xtitle("")  xlabel(0 "Not Childbearing Age Female" 1 "Childbearing Age Female") plotopts(color(grey%50)) ciopts(color(black)) 


gr save cbfem_int_chst_lo.gph, replace 

gr export cbfem_int_chst_lo.pdf, replace 

**family inc ints

margins, dydx(ban_last) at(faminc_75 = (0(1)1))

marginsplot, recast(bar) xtitle("") ytitle("Effect of Ban on Pr of Changing State Type") title("") xtitle("")  xlabel(0 "Bottom 3 Income Quartiles" 1 "Top Income Quartile") plotopts(color(grey%50)) ciopts(color(black)) 

gr save familyinc_int_chst_lo.gph, replace 

gr export familyinc_int_chst_lo.pdf, replace 

***appendix married models

reg changestatetype i.ban_last##i.baholder i.ban_last##i.cb_fem i.ban_last##c.faminc_75 i.ban_last##i.married homeowner nchild i.year i.laststate [pweight=asecwth], r
margins, dydx(ban_last) at(married = (0(1)1))
marginsplot, recast(bar) xtitle("") ytitle("Effect of Ban on Pr of Changing State Type") title("") xtitle("") xlabel(0 "Not Married" 1 "Married") plotopts(color(grey%50)) ciopts(color(black))
gr save married_int_chst.gph, replace 
gr export married_int_chst.pdf, replace 


******
*End
******************

clear 

